package reflect;

import java.lang.invoke.ConstantCallSite;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class cls=Class.forName("reflect.Person");

        Constructor c=cls.getConstructor();//获取无参构造器
        Object o=c.newInstance();//new person();
        System.out.println(o);

        Constructor c2=cls.getConstructor(String.class,int.class);
        Object o2=c2.newInstance("李四",19);//new Person("李四",19)
        System.out.println(o2);

        Constructor c3=cls.getConstructor(String .class);
        Object o3 = c3.newInstance("虎哥");
        System.out.println(o3);



    }
}
